{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "04209408",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extension Field:  QQ<sqrt(2)>\n",
      "a = ANP([MPQ(1,2)], [MPQ(1,1), MPQ(0,1), MPQ(-2,1)], QQ)\n",
      "b = ANP([MPQ(3,1)], [MPQ(1,1), MPQ(0,1), MPQ(-2,1)], QQ)\n",
      "a + b = ANP([MPQ(7,2)], [MPQ(1,1), MPQ(0,1), MPQ(-2,1)], QQ)\n",
      "a * b = ANP([MPQ(3,2)], [MPQ(1,1), MPQ(0,1), MPQ(-2,1)], QQ)\n"
     ]
    }
   ],
   "source": [
    "from sympy import symbols, QQ, RootOf\n",
    "\n",
    "# Define symbolic variables\n",
    "x = symbols('x')\n",
    "\n",
    "# Construct the algebraic extension QQ/(sqrt(2)) (which is a root of x^2 - 2 = 0) over the rational number field QQ\n",
    "ext_field = QQ.algebraic_field(RootOf(x**2 - 2, 1))\n",
    "\n",
    "# Output the extension field and algebraic element\n",
    "print(\"Extension Field: \", ext_field)\n",
    "# QQ<sqrt(2)>\n",
    "\n",
    "\n",
    "\n",
    "# Calculation on extention field\n",
    "a = ext_field(QQ(1, 2))\n",
    "b = ext_field(3)\n",
    "c = a + b\n",
    "d = a * b\n",
    "\n",
    "print(\"a =\", a)\n",
    "print(\"b =\", b)\n",
    "print(\"a + b =\", c)\n",
    "print(\"a * b =\", d)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c678725",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
